<template>
  <div id="provide">
    <h1 style="margin-bottom: 1%">供应商管理</h1>
    <div class="Prompt" v-show="state3">
      <span class="spanLeft">请填写供应商名称</span>
      <span
        class="iconfont icon-closel spanRight"
        @click="state = !state"
      ></span>
    </div>
    <div
      class="Opacity"
      v-show="state1"
      @click="
        state1 = !state1;
        state = !state;
      "
    ></div>
    <div class="Opacity" v-show="state2" @click="state2 = !state2"></div>
    <div style="border-top: 5px solid #d2d6de">
      <el-row class="Menu clear">
        <el-button
          class="iconfont icon-add-s"
          style="background-color: #00a65a"
          @click="addrow"
          >新增</el-button
        >
        <el-button
          class="iconfont icon-laihuijiantou"
          style="background-color: #208adb"
          @click="
            state = !state;
            state1 = !state1;
          "
          >转交</el-button
        >
        <el-button
          class="iconfont icon-sousuo"
          style="background-color: #6c7b8b"
          @click="state2 = !state2"
          >高级搜索</el-button
        >
        <el-button
          class="iconfont icon-export-xml"
          style="background-color: #00a65a"
          @click="Export"
          >导出</el-button
        >
        <el-button
          style="color: #444444; background-color: #f4f4f4"
          icon="el-icon-search"
          class="btnright"
          @click="ccoo"
        ></el-button>
        <el-input placeholder="查找..." v-model="findData"></el-input>
      </el-row>
      <el-table
        style="width: 100%"
        :header-cell-style="{ 'background-color': '#f7f7f7' }"
        :data="tableDatas"
      >
        <el-table-column prop="id" label="选择"></el-table-column>
        <el-table-column prop="types_title" label="类型"> </el-table-column>
        <el-table-column prop="supplier_name" label="供应商名称" width="180">
        </el-table-column>
        <el-table-column prop="level_name" label="级别"> </el-table-column>
        <el-table-column prop="supplier_types" label="类型"> </el-table-column>
        <el-table-column prop="status" label="状态"> </el-table-column>
        <el-table-column prop="emp_number" label="员工数量"> </el-table-column>
        <el-table-column prop="provinces" label="省市"> </el-table-column>
        <el-table-column prop="address" label="详细地址"> </el-table-column>
        <el-table-column prop="contact_name" label="联系人"> </el-table-column>
        <el-table-column prop="employee_realname" label="负责人">
        </el-table-column>
        <el-table-column prop="create_time" label="创建时间"> </el-table-column>
        <el-table-column prop="is_flow" label="跟进"> </el-table-column>
        <el-table-column prop="is_product" label="产品"> </el-table-column>
        <el-table-column prop="status_value" label="状态"> </el-table-column>
        <el-table-column label="操作" width="200px">
          <template slot-scope="scope">
            <span
              class="iconfont icon-xiugai xiugai"
              @click="reviseTable(scope.row)"
              ref="xiugai"
              >修改</span
            >
            <span
              class="iconfont icon-closel shanchu"
              @click="deleteTable(scope.row.id)"
              >删除</span
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="pageStyle">
      <ul class="ulLeft">
        <li>共条{{ tableLength }}|</li>
        <li>每页条{{ tableDatas.length }}|</li>
        <li>共{{ maxPage }}页</li>
      </ul>
      <ul class="ulRight">
        <el-button
          class="iconfont icon-zhishouye"
          @click="homePage"
          title="至首页"
        ></el-button>
        <el-button
          class="iconfont icon-triangle-left"
          @click="prevPage"
          title="上一页"
        ></el-button>
        <div style="display: inline-block" class="pages">
          <el-button
            ref="pages"
            v-for="(item, index) in maxPage"
            @click="pageSize(index)"
            :key="index"
            >{{ item }}</el-button
          >
        </div>
        <el-button
          class="iconfont icon-triangle-right"
          @click="nextPage"
          title="下一页"
        ></el-button>
        <el-button
          class="iconfont icon-zhiweiye"
          @click="lastPage"
          title="至尾页"
        ></el-button>
      </ul>
    </div>

    <div class="forwardStyle" v-show="state">
      <span
        class="iconfont icon-untitled96 zealot"
        style="cursor: pointer"
        @click="
          state = !state;
          state1 = !state1;
        "
      ></span>
      <div class="forwardDiv">
        <el-form class="Popout1">
          <el-form-item>
            <h3>部门</h3>
            <el-select
              v-model="departmentFrom.dept_title"
              placeholder="- - -请选择部门- - -"
              @change="staffRequests"
            >
              <el-option
                v-for="item in departmentFrom"
                :key="item.dept_title"
                :label="item.dept_title"
                :value="item.dept_title"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <h3>人员</h3>
            <el-select
              v-model="datas.region"
              placeholder="- - -请选择负责人- - -"
            >
              <el-option label="区域一" value="shanghai"></el-option>
              <el-option label="区域二" value="beijing"></el-option>
            </el-select>
          </el-form-item>
          <div class="submit">
            <el-button type="primary" @click="forward">转交</el-button>
          </div>
        </el-form>
      </div>
    </div>
    <div class="sqlccoos" v-show="state2">
      <span
        class="iconfont icon-untitled96 zealot1"
        style="cursor: pointer"
        @click="state2 = !state2"
      ></span>

      <div class="sqlccoosDiv">
        <el-form :inline="true" :model="heightData">
          <div class="minDiv">
            <h4>类型</h4>
            <el-select
              v-model="heightData.types_title"
              placeholder="- - -选择类型- - -"
            >
              <el-option
                v-for="item in TypeData"
                :key="item.types_title"
                :label="item.types_title"
                :value="item.types_title"
              ></el-option>
            </el-select>
          </div>
          <div class="minDiv">
            <h4>状态</h4>
            <el-select
              v-model="heightData.status_value"
              placeholder="- - -请选择状态- - -"
            >
              <el-option
                v-for="item in StateData"
                :key="item.status_value"
                :label="item.status_value"
                :value="item.status_value"
              ></el-option>
            </el-select>
          </div>
          <div class="minDiv">
            <h4>供应商</h4>
            <el-input v-model="heightData.supplier_name"></el-input>
          </div>
          <div class="minDiv">
            <h4>负责人</h4>
            <el-input v-model="heightData.employee_username"></el-input>
          </div>
          <div class="minDiv">
            <h4>时间起</h4>
            <el-date-picker
              v-model="heightData.startTime"
              type="date"
              placeholder="选择日期"
              style="width: 85%"
              @change="fomatTimeStart"
              value-format="yyyy-MM-dd HH:mm:ss"
            >
            </el-date-picker>
          </div>
          <div class="minDiv">
            <h4>时间止</h4>
            <el-date-picker
              v-model="heightData.endTime"
              type="date"
              placeholder="选择日期"
              style="width: 85%"
              @change="fomatTimeEnd"
              value-format="yyyy-MM-dd HH:mm:ss"
            >
            </el-date-picker>
          </div>
          <div class="minDivbut">
            <el-button type="primary" @click="sqlccoo">搜索</el-button>
            <el-button @click="Reset">重置</el-button>
          </div>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
import {
  SupplierRequest,
  deletes,
  QueryType,
  QueryState,
  department,
  staffRequest,
} from "../../utils/api/request.js";
export default {
  data() {
    return {
      //时间。。。

      //转交×开关
      state: false,
      //高级搜索开关
      state2: false,
      //遮盖k开关
      state1: false,
      //提示框开关
      state3: false,
      //默认类型数据
      TypeData: [],
      //默认状态数据
      StateData: [],
      //请求供应商数据
      tableData: { index: "", pageSize: "" },
      //查所有供应商需要的参数
      datas: {
        index: 1,
        pageSize: 5,
        search: null,
        employee_username: null,
        endTime: null,
        startTime: null,
        status_value: null,
        supplier_name: null,
        types_title: null,
        dept_title: null,
      },
      //高级查询
      heightData: {
        index: 1,
        pageSize: 5,
        search: null,
        employee_username: null,
        endTime: null,
        startTime: null,
        status_value: null,
        supplier_name: null,
        types_title: null,
      },
      //返回供应商数据
      tableDatas: [],
      //最大页
      maxPage: "",
      //总数据长度
      tableLength: "",
      //删除所需参数
      ids: [],
      //搜索input的条件
      findData: "",
      //部门默认值
      departmentFrom: [],
      //请求员工参数
      dept_title: "",
    };
  },
  created() {
    //初始化数据
    this.asksupplier();
    this.QueryTypes();
    this.QueryStates();
    this.departments();
  },
  methods: {
    //获取起始时间
    fomatTimeStart(vla) {
      this.heightData.startTime = vla;
      // console.log(this.datas.startTime);
    },
    //获取结束时间
    fomatTimeEnd(vla) {
      this.heightData.endTime = vla;
      // console.log(this.datas.endTime);
    },
    //请求类型默认值
    QueryTypes() {
      QueryType().then((data) => {
        this.TypeData = data.data.data;
      });
    },
    //请求状态默认值
    QueryStates() {
      QueryState().then((data) => {
        this.StateData = data.data.data;
      });
    },
    //请求转交部门默认值
    departments() {
      department().then((data) => {
        // console.log(data.data.data);
        this.departmentFrom = data.data.data;
      });
    },
    // 请求员工默认值
    staffRequests() {
      staffRequest(dept_title).then((data) => {
        // console.log(this.dept_title);
        // console.log(data);
      });
    },
    //请求所有供应商数据
    asksupplier() {
      SupplierRequest(this.datas).then((data) => {
        // 获取当页数据
        this.tableDatas = data.data.data.supplierVos;
        //获取最大页
        this.maxPage = Math.ceil(data.data.data.allCount / 5);
        //获取总数据
        this.tableLength = data.data.data.allCount;
      });
    },
    //点击修改时
    reviseTable(data) {
      this.$router.push({ path: "/reviseSuppliers", query: data });
    },
    //删除
    deleteTable(data) {
      this.ids.push(data);
      deletes({
        ids: this.ids,
      }).then((data) => {
        this.asksupplier();
      });
    },
    //至首页
    homePage() {
      this.datas.index = 1;
    },
    //至尾页
    lastPage() {
      this.datas.index = this.maxPage;
    },
    //上一页
    prevPage() {
      if (this.datas.index > 1) {
        this.datas.index--;
      }
    },
    //下一页
    nextPage() {
      if (this.datas.index < this.maxPage) {
        this.datas.index++;
      }
    },
    //页码点击
    pageSize(index) {
      //改变当点击页码
      this.datas.index = index + 1;
    },
    //input搜索事件
    ccoo() {
      this.datas.search = this.findData;
      SupplierRequest(this.datas).then((data) => {
        console.log(data);
      });
    },
    //新增事件
    addrow() {
      this.$router.push("/addSuppliers");
    },
    //转交提交事件,如果为空弹出提示
    forward() {
      this.state = !this.state;
      this.state1 = !this.state1;
    },
    //高级搜索搜索事件
    sqlccoo() {
      //高级搜索开关
      this.state2 = !this.state2;
      this.state1 = false;
      SupplierRequest(this.heightData).then((data) => {
        this.tableDatas = data.data.data.supplierVos;
      });
    },
    //重置事件清空input框
    Reset() {
      this.state2 = !this.state2;
    },
    //导出事件
    Export() {},
  },
  //监听页码变化刷新页面
  watch: {
    datas: {
      deep: true,
      handler() {
        this.asksupplier();
      },
    },
  },
};
</script>

<style scoped lang="less">
//修改删除
.xiugai {
  display: inline-block;
  font-size: 13px;
  background-color: #208adb;
  color: #fff;
  width: 50px;
  text-align: center;
  border-radius: 5px;
  cursor: pointer;
}
.shanchu {
  text-align: center;
  display: inline-block;
  font-size: 13px;
  background-color: #dd4b39;
  color: #fff;
  width: 50px;
  margin-left: 10%;
  border-radius: 5px;
  cursor: pointer;
}
//遮盖层
.Opacity {
  position: fixed;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  background-color: black;
  opacity: 0.6;
  z-index: 2;
}
//最大的div
#provide {
  padding: 1% 1% 0px 1%;
  background-color: #ecf0f5;
  //按钮表头
  .Menu {
    background-color: #ffffff;
    margin-bottom: 2px;
    .el-button {
      float: left;
      margin: 10px 0px;
      margin-left: 10px;
    }
    .iconfont {
      color: #ffffff;
    }
    .el-input {
      width: 200px;
      float: right;
      margin: 10px 0px;
    }
    .btnright {
      float: right;
      margin: 10px 0px;
      margin-right: 10px;
    }
  }
}
//页码div
.pageStyle {
  padding: 0 10px;
  height: 50px;
  background-color: #fafafa;
  .pages {
    line-height: 50px;
    text-align: center;
    padding: 0 10px;
    .el-button {
      font-weight: bold;
    }
  }
  .ulLeft {
    float: left;
    li {
      line-height: 50px;
      float: left;
      list-style: none;
    }
  }
  .ulRight {
    float: right;
    line-height: 50px;
    text-align: center;
    .el-button {
      font-size: 12px;
      padding: 5px;
    }
  }
}
//清除浮动类
.clear {
  clear: both;
  content: " ";
  display: block;
}
//转交框
.forwardStyle {
  opacity: 1;
  z-index: 3;
  width: 32%;
  background-color: #f9f9f9;
  position: absolute;
  border-radius: 7px;
  left: 50%;
  top: 25%;
  transform: translate(-50%);
  .forwardDiv {
    margin: 0 auto;
    width: 100%;
    height: 100%;
    .el-form {
      width: 100%;
      margin: 0 auto;
      .submit {
        display: block;
        margin-left: 77%;
        margin-bottom: 5%;
      }
      .el-form-item {
        margin-left: 2%;
        .el-select {
          width: 80%;
          margin-left: 8%;
        }
        h3 {
          display: block;
          margin-left: 8%;
        }
      }
    }
  }

  //icon转交叉图标
  .iconfont {
    background-color: #fff;
    border-radius: 50%;
    color: black;
    box-sizing: border-box;
  }
  //icon转交叉图标
  .zealot {
    padding: 5px;
    text-align: center;
    font-size: 25px;
    position: absolute;
    right: -15px;
    top: -15px;
  }
  .Popout1 {
    padding-top: 20px;
  }
  .formright {
    float: right;
    margin-right: 25px;
    margin-top: 10px;
  }
}
//高级搜素框
.sqlccoos {
  z-index: 3;
  width: 35%;
  background-color: #f9f9f9;
  position: absolute;
  border-radius: 5px;
  left: 50%;
  transform: translate(-50%);
  top: 28%;

  .sqlccoosDiv {
    width: 95%;
    margin: 5% 5%;
    .el-form {
      h4 {
        padding: 2% 0;
      }
      .minDiv {
        margin: 1% 0px;
        width: 50%;
        display: inline-block;
        .el-select {
          width: 85%;
        }
        .el-input {
          width: 85%;
        }
      }
      .minDivbut {
        margin-left: 67.7%;
        margin-top: 2%;
      }
    }
  }
  .zealot1 {
    position: absolute;
    font-size: 25px;
    background-color: #fff;
    border-radius: 50%;
    padding: 0.5%;
    top: 0.1%;
    right: 0.1%;
    color: black;
    box-sizing: border-box;
  }
}
//提示
.Prompt {
  width: 98%;
  margin: 0 auto;
  background-color: #dd4b39;
  color: #fff;
  height: 70px;
  margin-bottom: 1%;
  line-height: 70px;
  .spanLeft {
    float: left;
    margin-left: 1%;
  }
  .spanRight {
    float: right;
    margin-right: 1%;
    color: #b13c2e;
  }
}
</style>